package com.ruoyi.wxlogin.controller;


import com.ruoyi.wxlogin.pojo.WxUser;
import com.ruoyi.wxcommon.common.Result;
import com.ruoyi.wxlogin.mapper.WxMpUserMapper;
import com.ruoyi.wxlogin.mapper.WxUserMapper;
import com.ruoyi.wxlogin.service.IWxUserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx/user")
public class WxUserLoginController {
    @Autowired
    private IWxUserLoginService wxUserLoginService;
    @Autowired
    private WxMpUserMapper wxMpUserMapper;
    @Autowired
    private WxUserMapper wxUserMapper;
    @GetMapping("/getById")
    public WxUser getById(Integer wxId){
        return wxUserMapper.getByWxId(wxId);
    }
    @PostMapping("/pay")
    public WxUser getByOpenId(String openId){
        return wxUserMapper.byOpenId(openId);
    }
    @PostMapping("/add")
    public Result wxAuthorization(WxUser wxUser){
        return wxUserLoginService.login(wxUser);
    }
    @PostMapping("/update")
    public Result updateWxUser(WxUser wxUser){
        return wxUserLoginService.updateWxUser(wxUser);
    }
    @PostMapping("/authentication")
    public Result updateWxUserAuthentication(Integer id, String openId, Long studentNumber,String identificationNumber){
        return wxUserLoginService.updateWxUserAuthentication(id,openId,studentNumber,identificationNumber);
    }
    @GetMapping("/get/defAddress")
    public Result wxUser(Integer defaultAddress){
        return wxUserLoginService.getAddress(defaultAddress);
    }
    @PostMapping("/wxmpUser")
    public Result userInfo(Integer wxId){
        return Result.SUCCESS(wxMpUserMapper.byWxId(wxId));
    }
    @PostMapping("/update/defAddress")
    public Result defAddress(WxUser wxUser){
        return wxUserLoginService.wxUserInfo(wxUser);
    }
    @PostMapping("/get/id")
    public Result getId(Integer id){
        return Result.SUCCESS(wxUserMapper.getByWxId(id));
    }
}
